package com.example.rdcproject.ving.notes.dao;


import com.example.rdcproject.ving.notes.entity.Admin;
import com.example.rdcproject.ving.notes.service.ConnectionPool;
import com.example.rdcproject.ving.notes.util.DBUtils;
import com.example.rdcproject.ving.notes.view.Admin.AdminInteractionView;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class AdminDao {

    private Connection connection;

    private PreparedStatement statement;

    public AdminDao() {
    }

    //用户登录
    public boolean login(String account, String password) throws SQLException {
        Admin admin = new Admin();
        ConnectionPool connectionPool = null;
        try {
            connectionPool = ConnectionPool.getInstance();
            connection = connectionPool.getConnection();

            //判断查询结果
            if(admin.getAccount().equals(account)){
               if(admin.getPassword().equals(password)){
                   System.out.println("登录成功");
                   AdminInteractionView view = new AdminInteractionView();
                   return true;
               }else{
                   System.out.println("密码错误！");
                   return false;
               }
            }else {
                System.out.println("账号错误!");
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally{
            connectionPool.releaseConnection(connection);
            DBUtils.close(statement);

        }
        System.out.println("账号出现异常！");
        return  false;
    }
}
